package com.seari.tunnel.quartz;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.xml.bind.JAXBException;
import javax.xml.soap.SOAPException;

import org.springframework.beans.factory.annotation.Autowired;

import com.seari.tunnel.entity.RecordHistory;
import com.seari.tunnel.entity.job.OPCData;
import com.seari.tunnel.service.IJOBService;
import com.seari.tunnel.service.IOperatMaintenanceService;

public class DataAcquisition {
	private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	@Autowired
	IJOBService jobService;
	@Autowired
	IOperatMaintenanceService operatMaintenanceService;
	
	public void acquisition() throws SOAPException, IOException, JAXBException{
		List<OPCData> dataSource = new ArrayList<OPCData>();
		jobService.browse("", dataSource);
		jobService.read(dataSource);
		Date date = new Date();
		for(int i=0;i<dataSource.size();i++){
			if("DEMO.temp1".equals(dataSource.get(i).getOPCName())){
				RecordHistory rh = new RecordHistory();
				rh.setName("温度");
				rh.setValue(dataSource.get(i).getOPCValue());
				rh.setTime(sdf.format(date));
				operatMaintenanceService.addRecordHistory(rh);
			}
			if("DEMO.wet1".equals(dataSource.get(i).getOPCName())){
				RecordHistory rh = new RecordHistory();
				rh.setName("湿度");
				rh.setValue(dataSource.get(i).getOPCValue());
				rh.setTime(sdf.format(date));
				operatMaintenanceService.addRecordHistory(rh);
			}
			if("DEMO.O2".equals(dataSource.get(i).getOPCName())){
				RecordHistory rh = new RecordHistory();
				rh.setName("氧气");
				rh.setValue(dataSource.get(i).getOPCValue());
				rh.setTime(sdf.format(date));
				operatMaintenanceService.addRecordHistory(rh);
			}
			if("DEMO.krqt".equals(dataSource.get(i).getOPCName())){
				RecordHistory rh = new RecordHistory();
				rh.setName("可燃气体");
				rh.setValue(dataSource.get(i).getOPCValue());
				rh.setTime(sdf.format(date));
				operatMaintenanceService.addRecordHistory(rh);
			}
			if("DEMO.level".equals(dataSource.get(i).getOPCName())){
				RecordHistory rh = new RecordHistory();
				rh.setName("液位");
				rh.setValue(dataSource.get(i).getOPCValue());
				rh.setTime(sdf.format(date));
				operatMaintenanceService.addRecordHistory(rh);
			}
		}
	}
}
